﻿using System;
using System.Collections.Generic;
using System.Text;

namespace Chat.Common
{

    /// <summary>
    /// base64编码解码包装类
    /// </summary>
    public static class Base64
    {
        /// <summary>
        /// 把字符串用UTF8 base64编码的字符串
        /// </summary>
        /// <param name="str"></param>
        /// <returns></returns>
        public static string Encode(string str)
        {
            if (string.IsNullOrEmpty(str))
                return str;
            return Convert.ToBase64String(System.Text.Encoding.UTF8.GetBytes(str));
        }
        /// <summary>
        /// 把base编码的字符串还原到UTF8字符串
        /// </summary>
        /// <param name="base64Str"></param>
        /// <returns></returns>
        public static string Decode(string base64Str)
        {
            if (string.IsNullOrEmpty(base64Str))
                return base64Str;
            return System.Text.Encoding.UTF8.GetString(Convert.FromBase64String(base64Str));
        }
    }
}
